﻿using System;

namespace System.Windows.Input
{

    public abstract class CommandBase : CommandBase<Object>
    {
        public CommandBase() : this(true) { }

        public CommandBase(bool isActive)
            : base(isActive) { }


#region Additional Methods

        public virtual bool CanExecute()
        {
            return IsActive && OnCanExecute(); 
        }

        public virtual void Execute()
        {
            if (CanExecute())
            {
                OnExecute();
                OnCommandExecuted(new CommandEventArgs(null));
            }
        }

        public override void Execute(object parameter)
        {
            Execute();
        }

#endregion

#region Abstract Methods

        protected abstract bool OnCanExecute();

        protected abstract void OnExecute();

#endregion

#region Overrides

        protected override bool OnCanExecute(object parameter)
        {
            return CanExecute();      // ignores the parameter
        }

        protected override void OnExecute(object parameter)
        {
            Execute();              // ignores the parameter
        }

#endregion

    }
}
